<?php include_partial('global/flash') ?>
<?php include_partial('global/navbar') ?>

<div class="next_head">
    <div class="wrap">
        <a class="on" href="/account/myloan">还款中</a>
        <a href="/account/published">已发布</a>
    </div>
</div>


<div class="content_nav">
    <div class="tag_nav wrap">
        <div class="col-xs-12 pd-n">
            <table class="table">
                <thead>
                    <tr>
                        <th colspan="6"><a href="/project/index/@Model.ProjectId" target="_blank"><?php echo $loan->getTitle();?></a></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td width="100"><span class="tit-p">借款金额：</span></td>
                        <td><span class="alt-p"><?php echo number_format($loan->getMoney(),2);?></span></td>
                        <td width="100"><span class="tit-p">年利率：</span></td>
                        <td><span class="alt-p"><?php echo $loan->getMoneyRate()?></span></td>
                        <td width="100"><span class="tit-p">期限：</span></td>
                        <td><span class="alt-p"><?php echo $loan->getTermNum()?><?php if($loan->getIsDay() == 0):?>月<?php else:?>天<?php endif;?></span></td>
                    </tr>
                    <tr>
                        <td><span class="tit-p">应付本息：</span></td>
                        <td><span class="alt-p"><?php echo number_format(bcadd($loan->getInterestSum(),$loan->getMoney(),sfConfig::get('app_value_bit')),2);?></span></td>
                        <td><span class="tit-p">已付本息：</span></td>
                        <td><span class="alt-p"><?php echo number_format($loan->getAlreadyPayMoney()->getCurrentMoney(),2);?></span></td>
                        <td><span class="tit-p">待还本息：</span></td>
                        <td><span class="alt-p"><?php echo $loan->getPrincipal(0)?></span></td>
                    </tr>
                </tbody>
            </table>
            <div id="item_back">
                <table class="table  table-hover table-bordered">
                    <thead>
                        <tr>
                            <th>还款日</th>
                            <th>未还金额/已还金额</th>
                            <th>未还本金</th>
                            <th>未还利息</th>
                            <th>状态</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if(!empty($list)): $change_status = "";$i=0;?>
                        <?php foreach($list as $one_result):?>
                            <?php 
                            if($one_result->getStatus() == 4){
                                $change_status = 4;
                                $i++;
                            }
                            $status = empty($change_status)?$one_result->getStatus():$change_status;
                            ?>
                            <?php 
                                
                            ?>
                            <tr>
                                <td><?php echo date("Y-m-d",  strtotime($one_result->getCurrentEndTime()))?></td>
                                <td><?php if($status != 0 && $status != 2):?><?php echo number_format(0,2);?><?php else:?><?php echo number_format($one_result->getCurrentMoney(),2);?><?php endif;?>/<?php echo $one_result->getAlreadyPay();?></td>
                                <td><?php if($status != 0 && $i <= 1):?><?php echo number_format(0,2);?><?php else:?><?php echo number_format($one_result->getCurrentPrincipalMoney(),2);?><?php endif;?></td>
                                <td><?php if($status == 0 && $i <= 1):?><?php echo number_format($one_result->getCurrentInterestMoney(),2);?><?php else:?><?php echo number_format(0,2);?><?php endif;?></td>
                                <td><?php echo $one_result->getStatusName($status)?></td>
                            </tr>
                        <?php endforeach;?>
                        <?php endif;?>
                    </tbody>
                </table>
            </div>
            <?php if($loan->getStatus() != 5):?>
                <form id="submitform" class="form-horizontal" role="form" action="<?php echo url_for('account/repay')?>" method="POST">
                    <input type="hidden" name="loan_id" value="<?php echo $loan->getId()?>" checked>
                    <div class="form-group">
                        <label class="col-xs-2 control-label tit-p">您的账户余额：</label>
                        <div class="col-xs-10">
                            <p class="alt-p form-control-static"><strong><?php echo number_format($user_account->getRemainingMoney(),2)?></strong></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPassword3" class="col-xs-2 control-label tit-p">选择还款状态：</label>
                        <div class="col-xs-10">
                            <div class="radio_nav on">
                                <div class="radio">
                                    <label>
                                        <input type="radio" name="RepaymentType" value="1" checked />
                                        只还当期
                                    </label>
<!--                                    <div class="backcont">
                                        
                                        <span class="alt-p">1</span>&nbsp;&nbsp;<span class="tit-p">2</span>
                                    </div>-->
                                </div>
                            </div>
                           <?php if(strtotime($loan->getDateTimeObject('created_at')->format('Y-m-d H:i:s')) > 1414771200 ): ?>
                                <div class="radio_nav">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="RepaymentType" value="2" />
                                            提前还清所有欠款
                                        </label>
                                        <div class="backcont">
                                            <span class="alt-p"></span><span class="tit-p">（提前还款，共支付本息 </span><span class="alt-p"><?php echo $current_money?></span><span class="tit-p">）</span>
                                        </div>
                                    </div>
                                </div>
                           <?php endif;?>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-offset-2 col-sx-10">
                           <?php if($user_account->getRemainingMoney() <= 0):?>

                                <span class="alt-p">余额不足，请先进行<a href="<?php echo url_for('account/recharge')?>">充值</a></span>
                            <?php else:?>

                                <button type="submit" class="btn btn-primary btn-lg repaymentbtn" id="repaymentBtn"  onclick="$(this).attr('disabled',true);$('#submitform').submit();">还款</button>
                            <?php endif;?>
                        </div>
                    </div>
                </form>
                <?php endif;?>

<!--            @if (Model.ResponseStatus.ErrorCode == ResultCode.Success.ToString())
            { 
                <div class="alert alert-success">@Model.ResponseStatus.Message</div>
            }
            else if (Model.ResponseStatus.ErrorCode == ResultCode.Fail.ToString())
            {
                <div class="alert alert-danger">@Model.ResponseStatus.Message</div>
            }-->

        </div>
    </div>
</div>
<script >
    $("#10009").addClass("on");
</script>
